# 反转从位置 m 到 n 的链表。请使用一趟扫描完成反转。
#
#  说明:
# 1 ≤ m ≤ n ≤ 链表长度。
#
#  示例:
#
#  输入: 1->2->3->4->5->NULL, m = 2, n = 4
# 输出: 1->4->3->2->5->NULL
#  Related Topics 链表
#  👍 491 👎 0


# leetcode submit region begin(Prohibit modification and deletion)
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None
from myself.listnode import ListNode


# todo 链表
class Solution:

    def reverseBetween(self, head: ListNode, m: int, n: int) -> ListNode:

        if not head or m == 1:
            return head

        count = 1
        prev = None
        curr = head
        next = head.next
        while next:
            if count < m:
                count += 1

# leetcode submit region end(Prohibit modification and deletion)
